home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / gifshowr.arj / GIFFER.BAS
BASIC Source File  |  1993-05-07  |  5KB  |  254 lines

  1. '
  2. ' 07-05-93. 13:57:41 GIFFER.TBB
  3. 'This is , again, a real neat source by Rich Geldreich.
  4. 'Translated to PB3 by Thaddy de Koning.
  5. 'Yep, it works in screen 13!
  6. 'So pb has no screen 13?
  7. 'A small interrupt call to the videointerrupt does the job.
  8. 'It can be modified to run even faster, but it's pretty fast as it is.
  9. 'You DON'T need to link it with the graphics lib, because none of the
  10. 'graphics commands are used.
  11.  
  12. 'Cheap, no frills GIF decompressor for the VGA's 320x200x256 mode.
  13. 'By Rich Geldreich 1992 (Public domain, use as you wish.)
  14. $LIB ALL OFF
  15. $OPTIMIZE SPEED
  16. '$CPU 80386
  17.  
  18. DEFINT A-Z
  19. DIM Prefix(4095), Suffix(4095), OutStack(4095), ShiftOut(8)
  20. DIM Ybase AS word, Powersof2(11) AS integer, WorkCode AS integer
  21.  
  22. FOR A = 0 TO 7
  23.   ShiftOut(8 - A) = 2 ^ A
  24. NEXT
  25.  
  26. FOR A = 0 TO 11
  27.   Powersof2(A) = 2 ^ A
  28. NEXT
  29.  
  30. A$ = COMMAND$
  31. IF A$ = "" THEN
  32.   INPUT "GIF file"; A$
  33.   IF A$ = "" THEN
  34.     END
  35.   END IF
  36. END IF
  37.  
  38. IF INSTR(A$, ".") = 0 THEN
  39.   A$ = A$ + ".gif"
  40. END IF
  41.  
  42. OPEN A$ FOR BINARY AS #1
  43. GET$ #1,6, A$
  44. IF A$ <> "GIF87a" THEN
  45.   PRINT "Not a GIF87a file."
  46.   END
  47. END IF
  48. GET #1, , TotalX
  49. GET #1, , TotalY
  50.  
  51. GOSUB GetByte
  52.  
  53. NumColors = 2 ^ ((a AND 7) + 1)
  54. NoPalette = (a AND 128) = 0
  55. GOSUB GetByte
  56. Background = a
  57. GOSUB GetByte
  58. IF a <> 0 THEN
  59.   PRINT "Bad screen descriptor."
  60.   END
  61. END IF
  62.  
  63. IF NoPalette = 0 THEN
  64.   P$ = SPACE$(NumColors * 3)
  65.   GET #1, , P$
  66. END IF
  67.  
  68. DO
  69.   GOSUB GetByte
  70.   IF a = 44 THEN
  71.     EXIT DO
  72.   ELSEIF a <> 33 THEN
  73.     PRINT "Unknown extension type."
  74.     END
  75.   END IF
  76.   GOSUB GetByte
  77.   DO
  78.     GOSUB GetByte
  79.      GET$ #1,a , A$
  80.   LOOP UNTIL a = 0
  81. LOOP
  82. GET #1, , XStart
  83. GET #1, , YStart
  84. GET #1, , XLength
  85. GET #1, , YLength
  86. XEnd = XStart + XLength
  87. YEnd = YStart + YLength
  88. GOSUB GetByte
  89. IF a AND 128 THEN
  90.   PRINT "Can't handle local colormaps."
  91.   END
  92. END IF
  93. Interlaced = a AND 64
  94. PassNumber = 0
  95. PassStep = 8
  96. GOSUB GetByte
  97. ClearCode = 2 ^ a
  98. EOSCode = ClearCode + 1
  99. FirstCode = ClearCode + 2
  100. NextCode = FirstCode
  101. StartCodeSize = a + 1
  102. CodeSize = StartCodeSize
  103. StartMaxCode = 2 ^ (a + 1) - 1
  104. MaxCode = StartMaxCode
  105. BitsIn = 0
  106. BlockSize = 0
  107. BlockPointer = 1
  108. X = XStart
  109. Y = YStart
  110. Ybase = Y * 320&
  111.  
  112. 'kick into screen 13
  113.  
  114. Reg 1,&h0013
  115. call interrupt &h10
  116.  
  117. DEF SEG = &HA000
  118. IF NoPalette = 0 THEN
  119.   OUT &H3C7, 0
  120.   OUT &H3C8, 0
  121.   FOR A = 1 TO NumColors * 3
  122.     OUT &H3C9, ASC(MID$(P$, A, 1)) \ 4
  123.   NEXT
  124. END IF
  125.  
  126. DO
  127.   GOSUB GetCode
  128.   IF Code <> EOSCode THEN
  129.     IF Code = ClearCode THEN
  130.       NextCode = FirstCode
  131.       CodeSize = StartCodeSize
  132.       MaxCode = StartMaxCode
  133.       GOSUB GetCode
  134.       CurCode = Code
  135.       LastCode = Code
  136.       LastPixel = Code
  137.       IF X < 320 THEN
  138.         POKE X + Ybase, LastPixel
  139.       END IF
  140.         INCR X
  141.       IF X = XEnd THEN
  142.         GOSUB NextScanLine
  143.       END IF
  144.     ELSE
  145.       CurCode = Code
  146.       StackPointer = 0
  147.       IF Code > NextCode THEN           'bad GIF if this happens
  148.         EXIT DO
  149.       END IF
  150.       IF Code = NextCode THEN
  151.         CurCode = LastCode
  152.         OutStack(StackPointer) = LastPixel
  153.           INCR StackPointer
  154.       END IF
  155.       DO WHILE CurCode >= FirstCode
  156.         OutStack(StackPointer) = Suffix(CurCode)
  157.           INCR StackPointer
  158.         CurCode = Prefix(CurCode)
  159.       LOOP
  160.       LastPixel = CurCode
  161.       IF X < 320 THEN
  162.         POKE X + Ybase, LastPixel
  163.       END IF
  164.         INCR X
  165.       IF X = XEnd THEN
  166.         GOSUB NextScanLine
  167.       END IF
  168.       FOR A = StackPointer - 1 TO 0 STEP -1
  169.         IF X < 320 THEN
  170.           POKE X + Ybase, OutStack(A)
  171.         END IF
  172.           INCR X
  173.         IF X = XEnd THEN
  174.           GOSUB NextScanLine
  175.         END IF
  176.       NEXT
  177.       IF NextCode < 4096 THEN
  178.         Prefix(NextCode) = LastCode
  179.         Suffix(NextCode) = LastPixel
  180.           INCR NextCode
  181.         IF NextCode > MaxCode AND CodeSize < 12 THEN
  182.              INCR CodeSize
  183.              SHIFT LEFT MAXCODE,1
  184.              INCR MAXCODE
  185.         END IF
  186.       END IF
  187.       LastCode = Code
  188.     END IF
  189.   END IF
  190. LOOP UNTIL DoneFlag OR Code = EOSCode
  191. BEEP
  192.  
  193. A$ = INPUT$(1)
  194.  
  195. reg 1,&h0003
  196. call interrupt &h10
  197. END
  198.  
  199. GetByte:
  200. GET #1,, a?
  201. a=a?
  202. RETURN
  203.  
  204. NextScanLine:
  205. IF Interlaced THEN
  206.   Y = Y + PassStep
  207.   IF Y >= YEnd THEN
  208.      INCR PassNumber
  209.     SELECT CASE PassNumber
  210.     CASE 1
  211.       Y = 4
  212.       PassStep = 8
  213.     CASE 2
  214.       Y = 2
  215.       PassStep = 4
  216.     CASE 3
  217.       Y = 1
  218.       PassStep = 2
  219.     END SELECT
  220.   END IF
  221. ELSE
  222.   INCR Y
  223. END IF
  224. X = XStart
  225. Ybase = Y * 320&
  226. DoneFlag = Y > 199
  227. RETURN
  228. GetCode:
  229. IF BitsIn = 0 THEN
  230.   GOSUB ReadBufferedByte
  231.   LastChar = A
  232.   BitsIn = 8
  233. END IF
  234. WorkCode = LastChar \ ShiftOut(BitsIn)
  235. DO WHILE CodeSize > BitsIn
  236.   GOSUB ReadBufferedByte
  237.   LastChar = A
  238.   WorkCode = WorkCode OR LastChar * Powersof2(BitsIn)
  239.   INCR BitsIn,8
  240. LOOP
  241. BitsIn = BitsIn - CodeSize
  242. Code = WorkCode AND MaxCode
  243. RETURN
  244. ReadBufferedByte:
  245. IF BlockPointer > BlockSize THEN
  246.   GOSUB GetByte
  247.   BlockSize = A
  248.   GET$ #1,blocksize , A$
  249.   BlockPointer = 1
  250. END IF
  251. A = ASC(MID$(A$, BlockPointer, 1))
  252. INCR BlockPointer
  253. RETURN
  254.